using System.IO;
using UnityEngine;
using UnityEngine.UI;
using XLua;
using Newtonsoft.Json;
using System;

public class TestTwo : MonoBehaviour
{
    public InputField testField;
    LuaEnv luaEnv;
    LuaFunction luaField;
    LuaFunction luaButton;
    LuaFunction onUpDate;
    LuaFunction loadJson;
    // Start is called before the first frame update
    void Start()
    {
        luaEnv = new LuaEnv();
        luaEnv.AddLoader((ref string s) =>
        {
            return File.ReadAllBytes(Application.dataPath + "/Lua/" + s + ".lua");
        });
        luaEnv.DoString("require'UITest'");
        luaField = luaEnv.Global.Get<LuaFunction>("LuaField");
        luaButton = luaEnv.Global.Get<LuaFunction>("LuaButton");
        onUpDate = luaEnv.Global.Get<LuaFunction>("OnUpDate");
        loadJson = luaEnv.Global.Get<LuaFunction>("LoadJson");

        if (loadJson != null)
        {
            loadJson.Call();
        }
        if (luaField != null)
        {
            luaField.Call(this,testField);
        }
        if (luaButton != null)
        {
            luaButton.Call();
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (onUpDate != null)
        {
            onUpDate.Call();
        }
    }
}
